<?php 
require_once $_SERVER['DOCUMENT_ROOT'].'/inc/core/env.inc.php';

$return["success"] = false;
$return["html"] = null;
$return["error"] = null;

if ($_USER->asPermission('set_permissions')) {
	
	$return['html'] = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-rows.tag.html');

	$row = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-row.tag.html');
	$col = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-col.tag.html');
	
	$frmAdd = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-frm-add-permission.tag.html');
	$frmAdd = '<li>'.$frmAdd.'</li>';
	$return['html'] = str_replace($_TAGS["admin-frm-add-permission"], $frmAdd, $return['html']);
	
	$rows = '<li><div><b>Name</b></div><div><b>Description</b></div><div><b>Not traslate description</b></div><br class="clearboth"></li>';
	
	$sql = "SELECT * FROM ".$_DB->getPrefix()."permissions ORDER BY name ASC";
	$res = $_DB->query($sql);
	
	foreach($res as $ele) {
		
		$rowContent  = str_replace($_TAGS["share-content-col"], $ele["name"], $col);
		$rowContent .= str_replace($_TAGS["share-content-col"], $_TRANSLATE->traslate($ele["description"], $_SESSION["LANGUAGE"]), $col);
		$rowContent .= str_replace($_TAGS["share-content-col"], $ele["description"], $col);
		
		
		$rowTmp = str_replace($_TAGS['admin-row-class'], '', $row);
		$rows .= str_replace($_TAGS['share-content-columns'], $rowContent, $rowTmp);
	}
	
	$return['html'] = str_replace($_TAGS['admin-rows'], $rows, $return['html']);
	
	$return["success"] = true;
} else {
	$return["error"] = 'Error not modify permission.';
}

echo '('.json_encode($return).')';
?>